﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Model_Layer
{
    class GraphRepresentation : IGraph 
    {
        private List<LinkedList<Airport>> adjacentAirports;
        private IList<Airport> airportList;
        //Use 'getAllAirport' method to retrieve a list all Airports from Airport db, 
        //then store the total number of Airports in 'totalNumOfAirports' variable.
        private int totalNumOfAirports; 
        

        //Constructor
        public GraphRepresentation(int totalNumOfAirports)
        {
            Initialize(totalNumOfAirports);
        }

        //Initialize Nodes and Neighbours 
        private void Initialize(int totalNumOfAirports)
        {
            airportList = new List<Airport>(totalNumOfAirports);
            adjacentAirports = new List<LinkedList<Airport>>(totalNumOfAirports);
            for (int i = 0; i < totalNumOfAirports; i++)
            {
                adjacentAirports.Add(new LinkedList<Airport>());
            }
        }



        public void AddAirport(Airport airport)
        {
            airportList.Add(airport);
        }


        public void AddFlight(Airport startAirport, Airport stopAirport, int travelTime)
        {
            int startIndex = airportList.IndexOf(startAirport);
            adjacentAirports[startIndex].AddFirst(stopAirport);
        }


    }
}

